﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Computer_Manager.DAL;
using Computer_Manager.DTO;
using DevExpress.XtraEditors;
using System.Windows.Forms;

namespace Computer_Manager.BUS
{
    class BUS_user
    {
        DAL_user dal = new DAL_user();

        public bool user_insert(DTO_user obj)
        {
            try
            {
                dal.user_insert(obj);
            }
            catch (Exception e)
            {

                XtraMessageBox.Show(e.Message, "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            return true;

        }

        public bool user_Update(DTO_user obj)
        {
            try
            {
                dal.user_Update(obj);
            }
            catch (Exception e)
            {

                XtraMessageBox.Show(e.Message, "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            return true;
        }
        public bool user_ChangePass(DTO_user obj)
        {
            try
            {
                dal.user_ChangePass(obj);
            }
            catch (Exception e)
            {

                XtraMessageBox.Show("Lổi: "+e.Message, "Đổi mật khẩu không thành công", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            return true;
        }

        public bool user_Delete(DTO_user obj)
        {
            try
            {
                dal.user_Delete(obj);
            }
            catch (Exception e)
            {

                XtraMessageBox.Show(e.Message, "Xóa không công", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }

        public DataTable GetByID(DTO_user obj)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = dal.GetByID(obj);
            }
            catch (Exception)
            {

                throw;
            }
            return dt;
        }
        public DataTable CheckLogin(DTO_user obj)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = dal.CheckLogin(obj);
            }
            catch (Exception e)
            {

                XtraMessageBox.Show(e.Message, "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return dt;
        }

        public DataTable GetByUserName(DTO_user obj)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = dal.GetByUserName(obj);
            }
            catch (Exception)
            {

                throw;
            }
            return dt;
        }

        public DataTable GetAll()
        {
            DataTable dt = new DataTable();
            try
            {
                dt = dal.GetAll();

            }
            catch (Exception e)
            {

                XtraMessageBox.Show(e.Message, "Xóa không công", MessageBoxButtons.OK, MessageBoxIcon.Error);
                
            }
            return dt;
        }
    }
}
